package com.ccl.iot.object;

/**
 * 设备MAC地址结构
 * 组合式为：	iPart[0]:iPart[1]:iPart[2]:iPart[3]:iPart[4]:iPart[5]
 * 例如：		FF:FF:FF:FF:FF:FF
 */
public class IOTDeviceMAC {
	private long iMAC = 0;
	private byte iPart[] = new byte[6];
	
	public IOTDeviceMAC(long aMAC){
		iMAC = aMAC;
		
		iPart[0] = (byte) (aMAC & 0xFF);
		iPart[1] = (byte) ((aMAC >> 8) & 0xFF);
		iPart[2] = (byte) ((aMAC >> 16) & 0xFF);
		iPart[3] = (byte) ((aMAC >> 24) & 0xFF);
		iPart[4] = (byte) ((aMAC >> 32) & 0xFF);
		iPart[5] = (byte) ((aMAC >> 40) & 0xFF);
	}
	
	public long getLongMAC(){
		return iMAC;
	}

	@Override
	public String toString() {
		return iPart[0] + ":" + iPart[1] + ":" + iPart[2] + ":" + iPart[3] + ":" + iPart[4] + ":" + iPart[5];
	}

	@Override
	public boolean equals(Object aMAC) {
		if (!super.equals(aMAC)){
			if (aMAC != null){
				if (aMAC instanceof Long){
					return (Long)aMAC == iMAC;
				}else if (aMAC instanceof String){
					return aMAC.equals(this.toString());
				}
			}
		}else{
			return true;
		}
		
		return false;
	}
}
